home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <string.h>
- #include "exinterfmotif.h"
- #include "exbookglo.h"
-
-
- void index_add_demo(struct indexlist *ndxptr, struct icntmpltstruct *curicon)
- {
- struct iconstruct *tmpicon;
-
- /*
- printf("in index_add_demo ");
- printf(" keyword %s icon %s \n", ndxptr->string, curicon->nameptr->string);
- */
- tmpicon = ndxptr->icons;
- if (tmpicon == NULL)
- {
- tmpicon = (struct iconstruct *)malloc(sizeof(struct iconstruct) );
- ndxptr->icons = tmpicon;
- }
- else
- {
- while (tmpicon->nexticon != NULL)
- {
- tmpicon = tmpicon->nexticon;
- }
- tmpicon->nexticon = (struct iconstruct *)malloc(sizeof(struct iconstruct) );
- tmpicon = tmpicon->nexticon;
- }
- tmpicon->nexticon = NULL;
- tmpicon->iconptr = curicon;
- }
-
- void index_add_group(struct indexlist *ndxptr, struct grptmpltstruct *curgrp)
- {
- struct grpliststruct *tmpgrp;
-
- /*
- printf("in index_add_group ");
- printf(" keyword %s book %s \n", ndxptr->string, curgrp->nameptr->string);
- */
- tmpgrp = ndxptr->grps;
- if (tmpgrp == NULL)
- {
- tmpgrp = (struct grpliststruct *)malloc(sizeof(struct grpliststruct) );
- ndxptr->grps = tmpgrp;
- }
- else
- {
- while (tmpgrp->next != NULL)
- {
- tmpgrp = tmpgrp->next;
- }
- tmpgrp->next = (struct grpliststruct *)malloc(sizeof(struct grpliststruct) );
- tmpgrp = tmpgrp->next;
- }
- tmpgrp->next = NULL;
- tmpgrp->grpptr = curgrp;
- }
-
- struct indexlist *(find_keyword_int(int number) )
- {
- struct indexlist *cur;
- int count;
-
- cur = Index;
- count = 0;
- while (cur!= NULL && number != count)
- {
- cur = cur -> next;
- count++;
- }
-
- /*
- if (cur != NULL)
- cur->count +=1;
- */
- return(cur);
- }
-
- struct indexlist *(find_keyword(s) )
- char *s;
- {
- struct indexlist *cur;
- int cmp_result = 100;
-
- /* is this string already in the index? */
- cur = Index;
- while (cur != NULL && (cmp_result = strcasecmp(s,cur->string)) > 0)
- cur = cur->next;
- if (cmp_result == 0) /* the string is in the index */
- return(cur);
- else
- return(NULL);
- }
-
- struct indexlist *remove_keyword(iptr)
- struct indexlist *iptr;
- {
- struct indexlist *tmpptr;
- int width;
-
- iptr->count -= 1;
- if (iptr->count <= 0)
- {
- tmpptr = Index;
- if (tmpptr == iptr)
- {
- Index = iptr->next;
- }
- else
- {
- while (tmpptr->next != iptr)
- {
- tmpptr = tmpptr->next;
- }
- tmpptr->next = iptr->next;
- }
- free(iptr->string);
- free(iptr);
- iptr = NULL;
- }
- return(iptr);
- }
-
- remove_keyword_icon(ndxptr, icnptr)
- struct indexlist *ndxptr;
- struct icntmpltstruct *icnptr;
- {
- struct iconstruct *tmpicon, *previcon;
- Boolean done = FALSE;
-
- ndxptr = remove_keyword(ndxptr);
- if (ndxptr != NULL) /* take the icon out of the keyword's list of icons */
- {
- previcon = NULL;
- tmpicon = ndxptr->icons;
- while (tmpicon != NULL && !done)
- {
- if (tmpicon->iconptr == icnptr)
- {
- done = TRUE;
- if (previcon == NULL)
- ndxptr->icons = tmpicon->nexticon;
- else
- previcon->nexticon = tmpicon->nexticon;
- }
- previcon = tmpicon;
- tmpicon = tmpicon->nexticon;
- }
- if (done)
- free(previcon);
- }
- }
-
- remove_keyword_group(ndxptr, grpptr)
- struct indexlist *ndxptr;
- struct grptmpltstruct *grpptr;
- {
- struct grpliststruct *tmpgrp, *prevgrp;
- Boolean done = FALSE;
-
- ndxptr = remove_keyword(ndxptr);
- if (ndxptr != NULL)
- {
- prevgrp = NULL;
- tmpgrp = ndxptr->grps;
- while (tmpgrp != NULL && !done)
- {
- if (tmpgrp->grpptr == grpptr)
- {
- done = TRUE;
- if (prevgrp == NULL)
- ndxptr->grps = tmpgrp->next;
- else
- prevgrp->next = tmpgrp->next;
- if (tmpgrp->next != NULL)
- tmpgrp->next->prev = prevgrp;
- }
- prevgrp = tmpgrp;
- tmpgrp = tmpgrp->next;
- }
- if (done)
- free(prevgrp);
- }
- }
-
- /****************************************************
- *
- * delete_keywords(void * ptr, int type) if type = 0, ptr = icntmpltstruct.
- * delete_keywords(void * ptr, int type) if type = 1, ptr = grptmpltstruct.
- *
- ***************************************************/
- void delete_keywords(void * ptr, int type)
- {
- struct wordlist *wrdptr;
- struct wordlist *wrd2;
- struct icntmpltstruct *icnptr;
- struct grptmpltstruct *grpptr;
-
- if (type == 0)
- {
- icnptr = (struct icntmpltstruct *)ptr;
- wrdptr = icnptr->keywords;
- }
- else
- {
- grpptr = (struct grptmpltstruct *)ptr;
- wrdptr = grpptr->keywords;
- }
- while (wrdptr != NULL)
- {
- wrd2 = wrdptr->next;
- if (type == 0)
- {
- remove_keyword_icon(wrdptr->indexptr,icnptr);
- }
- else
- {
- remove_keyword_group(wrdptr->indexptr,grpptr);
- }
- free(wrdptr);
- wrdptr = wrd2;
- }
- }
-
- void check_index()
- {
- struct indexlist *ndxptr;
- int n;
-
- ndxptr = Index;
- n = 0;
- while (ndxptr != NULL)
- {
- if (ndxptr->count == 0)
- remove_keyword(ndxptr);
- else
- {
- ndxptr->num = n;
- n++;
- }
- ndxptr = ndxptr->next;
- }
- }
-
- struct indexlist *add_keyword(s)
- char *s;
- {
- struct indexlist *cur, *newptr, *insert;
- int cmp_result = 100;
- int width;
-
- /* is this string already in the index? */
- cur = Index;
- insert = NULL;
- while (cur != NULL && (cmp_result = strcasecmp(s,cur->string)) > 0)
- {
- insert = cur;
- cur = cur->next;
- }
- if (cmp_result != 0) /* the string is not in the index */
- {
- newptr = (struct indexlist *)malloc(sizeof(struct indexlist));
- newptr->next = NULL;
- newptr->string = (char *)malloc(strlen(s)+1);
-
- newptr->string = strcpy(newptr->string, s);
- newptr->found_on_page = NULL;
- newptr->group = NULL;
- newptr->icon = NULL;
- newptr->icons = NULL;
- newptr->grps = NULL;
- newptr->count = 1;
- if (Index == NULL)
- {
- Index = newptr;
- newptr->num = 0;
- }
- else
- {
- if (insert == NULL)
- {
- newptr->next = Index;
- Index = newptr;
- }
- else
- {
- insert->next = newptr;
- newptr->next = cur;
- newptr->num = insert->num+1;
- }
- }
- }
- else /* cmp_result == 0 */
- {
- newptr = cur;
- newptr->count += 1;
- }
-
- return(newptr);
- }
-
- void short_print_keywords()
- {
- struct indexlist *curword;
- int i;
-
- curword = Index;
- if (curword != NULL)
- printf(" INDEX: \n");
- i = 0;
- while (curword != NULL)
- {
- printf(" %d %s %d \n", i, curword->string, curword->count );
- i++;
- curword = curword->next;
- }
- printf(" \n\n");
- }
-
- void print_keywords()
- {
- struct indexlist *curword;
- struct wordlist *wrdptr;
- struct grpliststruct *tmpgrp;
- struct iconstruct *tmpicon;
- int i, count;
-
- curword = Index;
- if (curword != NULL)
- printf(" INDEX: \n");
- i = 0;
- while (curword != NULL)
- {
- printf(" %d %d %s %d occurences ",
- i, curword->num, curword->string, curword->count);
- if (curword->icon != NULL)
- printf(" Icon Name \n");
- if (curword->group != NULL)
- printf(" Book Name \n");
- tmpgrp = curword->grps;
- count = 0;
- printf(" Books: \n");
- while (tmpgrp != NULL)
- {
- printf(" %s \n", tmpgrp->grpptr->nameptr->string);
- count++;
- tmpgrp = tmpgrp->next;
- }
- printf(" total %d \n",count);
- tmpicon = curword->icons;
- count = 0;
- printf(" Icons: \n");
- while (tmpicon != NULL)
- {
- printf("\t\t %s \n", tmpicon->iconptr->nameptr->string);
- count ++;
- tmpicon = tmpicon->nexticon;
- }
- printf(" total %d \n",count);
- i++;
- printf("\n");
- curword = curword->next;
- }
- printf(" done printing index \n");
- }
-